package unit17.server;

import java.io.*;
import java.net.*;
import java.util.*;

public class EchoServerTest {
	public static void main(String[] args) throws IOException {
		try(ServerSocket s=new ServerSocket(8189)){
			try(Socket incoming=s.accept()){
				InputStream inputStream=incoming.getInputStream();
				OutputStream outputStream=incoming.getOutputStream();
				
				try(Scanner in=new Scanner(inputStream)){
					PrintWriter out=new PrintWriter(outputStream,true/*autoFlush*/);
					out.println("hello ! Enter BYE to exit!");
					
					boolean done=false;
					
					while(!done&&in.hasNextLine()){
						String line=in.nextLine();
						out.println("Echo:"+line);
						if(line.trim().equals("BYE"))
							done=true;
					}
				}
			}
		}
	}
}
